#ifndef TIMER_H
#define TIMER_H

#include <functional>
#include "Base/timestamp.h"
#include "Base/noncopyable.h"

namespace tiny_muduo
{
    class Timer : public NonCopyable
    {
    public:
        typedef std::function<void()> BasicFunc;
        
        Timer(Timestamp timestamp, BasicFunc&& cb, double interval = 0.0);

        void Restart(Timestamp now)
        {
            expiration_ = Timestamp::AddTime(now, interval_);
        }

        void Run() const
        {
            callback_();
        }

        Timestamp expiration() const { return expiration_; }
        bool repeat() const { return repeat_; }

    private:
        Timestamp expiration_;
        BasicFunc callback_;
        double interval_;
        bool repeat_;
    };
} // namespace tiny_muduo


#endif